import { applyMiddleware, createStore, compose } from 'redux'
import rootReducer from './reducers'
import thunk from 'redux-thunk';
const middleware = [thunk]
/**
 * 大概流程就是：store.dispatch=>action=>reducer=>state
 * 要改变的组件，它获取state和action，生成新的state
 * rootReducer,作用收到action以后必须给出一个新的state,这样view才会发生变化,这种state的计算过程就叫做reducer
 * {}为初始值
 * applyMiddleware将所有中间件组成一个数组
 */
const store = createStore(
    rootReducer,
    {},
    compose(
        applyMiddleware(...middleware),
        // 调试
        window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
    ))

export default store;